/*
 * Copyright 2011-2012 by RICHWARE SYSTEMS Corp., All rights reserved.
 * 
 * This software is the confidential and proprietary information of RICHWARE
 * SYSTEMS Corp. ("Confidential Information").
 */
package com.yonginitagmaker.util;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.view.Window;

import com.yonginitagmaker.R;

public class ProgressDialogUtil
{

	public static Dialog show(Context context, Dialog dialog, int layoutResId, OnDismissListener dismissListener, OnCancelListener cancelListener)
	{
		if(dialog != null)
		{
			if(!dialog.isShowing())
			{
				dialog.show();
			}
			return dialog;
		}

		try
		{
			if(layoutResId > 0)
			{
				dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
				dialog.setCancelable(true);
				dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
				dialog.setContentView(layoutResId);
			}
			else
			{
				// dialog = new ProgressDialog(context);
				// ((ProgressDialog)
				// dialog).setMessage("로딩중입니다.\n잠시만 기다려주시기 바랍니다.");
				dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
				dialog.setCancelable(true);
				dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
				dialog.setContentView(R.layout.widget_progress_bar);
			}

			if(cancelListener != null)
				dialog.setOnCancelListener(cancelListener);

			if(dismissListener != null)
				dialog.setOnDismissListener(dismissListener);

			dialog.show();

		}
		catch (Exception e)
		{

			e.printStackTrace();

		}

		return dialog;
	}

	public static Dialog showFull(Context context, Dialog dialog)
	{
		if(dialog != null)
		{
			if(!dialog.isShowing())
			{
				dialog.show();
			}
			return dialog;
		}

		try
		{
			dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
			dialog.setCancelable(true);
			dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
			dialog.setContentView(R.layout.widget_progress_bar);
			dialog.show();

		}
		catch (Exception e)
		{

			e.printStackTrace();

		}

		return dialog;
	}

	public static Dialog show(Context context, Dialog dialog, int layoutResId)
	{
		return show(context, dialog, layoutResId, null, null);
	}

	public static Dialog show(Context context, Dialog dialog, int layoutResId, OnDismissListener dismissListener)
	{
		return show(context, dialog, layoutResId, dismissListener, null);
	}

	public static Dialog show(Context context, Dialog dialog, int layoutResId, OnCancelListener cancelListener)
	{
		return show(context, dialog, layoutResId, null, cancelListener);
	}

	public static void dismiss(Dialog dialog)
	{
		try
		{

			if(dialog != null && dialog.isShowing())
				dialog.dismiss();

		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

	}

}
